
import time
import threading


class Profiler(threading.Thread):

	def __init__(self, bots, interval):
		threading.Thread.__init__(self)
		self.bots = bots
		self.interval = interval
		self.exist = True

	def run(self):
		while self.exist:
			time.sleep(self.interval)
			for bot in self.bots:
				bot.hitRate = bot.hitCount / (1.0 * self.interval)
				bot.msgRate = bot.msgCount / (1.0 * self.interval)
				print 'PROFILER %s: %.2f hits/sec, %.2f msgs/sec' % (bot.JID, bot.hitRate, bot.msgRate)
				bot.hitCount = 0
				bot.msgCount = 0
